package com.baturu.vin.honda.transformer;

import com.baturu.kit.kit.function.SafeFunction;
import com.baturu.vin.dto.superEPC.SEPCPartsDTO;
import com.baturu.vin.honda.constant.HondaDataVersionConstant;
import com.baturu.vin.honda.dto.SEPCHondaPartsInfoDTO;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author: chenjiahao
 * @Time: 2019/5/9
 */
public class SEPCPartsTransformer {
    public static final SafeFunction<SEPCHondaPartsInfoDTO, SEPCPartsDTO> PARTS_INFO_TO_SEPC_PARTS_INFO =
            input -> SEPCPartsDTO.builder()
                    .callout(input.getNplpartref())
                    .epcName(input.getXpartext())
                    .epcDesc(input.getEpcPartsNameCN())
                    .epcPartsImageDTOs(input.getEpcPartsImageDTOs())
//                    .imageUrl( input.getNpl() + "/IMGE/" + input.getNplblk())
                    .imageUrl(getImageURL(input.getDisk(),input.getNpl(),input.getNplblk()))
                    .partsCode(input.getNpartgenu())
                    .installNum(input.getXordergun())
                    .multiExtColor(input.getExtColor())
                    .multiInnerColor(input.getInnerColorType())
                    .btrPartsName(input.getBtrPartsName())
                    .build();

    public static String getImageURL(String disk, String npl, String imageName) {
        if (StringUtils.isBlank(disk) || StringUtils.isBlank(npl)) {
            return "";
        }
        String imageUrl = npl + "/IMGE/" + imageName;
        int ver = (int)Math.ceil(Float.parseFloat(disk) / 2.0f);
        if (ver>= HondaDataVersionConstant.PRE_FIVE_VER_URL) {
            imageUrl = ver+"/"+ imageUrl;
        }
        return  imageUrl;
    }
}
